<template>
  <div class="no-decoration">
    <c-section title="门店建设基本信息">
      <template v-slot:right>
        <c-abnormal-preview path="/storeConstruction/exceptionManage" :query="{ constCode: detail.constCode, functionModel: 'SHOP_DECORATION' }" />
      </template>
      <c-list ref="form" :model="formData" :rules="formRules" :column="3">
        <c-list-item label="门店编码" :value="detail.shopCode" />
        <c-list-item label="门店" :value="detail.shopName" />
        <c-list-item label="所属客户编码" :value="detail.clientCode" />
        <c-list-item label="所属客户" :value="detail.clientName" />
        <c-list-item label="所属办事处" :value="detail.officeName" />
        <c-list-item label="门店类型" dict-type-code="SHOP_TYPE" :value="detail.shopType" />
        <c-list-item label="门店业务类型" dict-type-code="BIZ_TYPE" :value="detail.shopBizType" />
        <c-list-item label="门店城市级别" dict-type-code="CITY_LEVEL" :value="detail.shopCityLevel" />
        <c-list-item label="门店详细地址" :value="detail.shopAddress" :span="3" />

        <c-list-item label="门店建设项目号" :value="detail.constCode" />
        <c-list-item label="报图类型" dict-type-code="MARKET_TYPE" :value="detail.marketType" />
        <c-list-item label="门店建设类型" dict-type-code="CONST_TYPE" :value="detail.constType" />
        <c-list-item label="商家类别" dict-type-code="BIZMAN_TYPE" :value="detail.bizmanType" />
        <c-list-item label="装修形式" dict-type-code="DECORATION_FORM" :value="detail.decorationFormCal || detail.decorationForm" />
        <c-list-item label="门店建设范围" dict-type-code="DECORATION_RANGE" :value="detail.decorationRange" />

        <c-list-item v-if="$route.query.type" :rules="[{ required: $route.query.type, message: '请选择客户经理', trigger: 'change' }]" label-width="100px" label="客户经理" prop="customerManagerCode">
          <c-single-dialog
            ref="formSupervisorCode"
            v-model="formData.customerManagerCode"
            :label.sync="formData.customerManagerName"
            :props="{label:'userName',value:'account'}"
            :focus-query="true"
            :multiple="false"
            :config="{
              title:'客户经理',
              width:'600px',
              interfacePath:`/slm-admin/api/v1/user/domainMarketingUser/page`,
              method:'post',
              filtersRaw:[],
              paramsRaw:{},
              setting:[
                {prop:'account',title:'编码',width:80},
                {prop:'userName',title:'名字',width:150},
                {prop:'orgName',title:'组织',width:120},
                {prop: 'phone', title: '电话', width: 150}
              ]
            }"
          />
        </c-list-item>
        <c-list-item v-if="$route.query.type" :rules="[{ required: $route.query.type, message: '请选择', trigger: 'change' }]" label="是否涉及扣款" prop="isRelateDeduction">
          <div>
            <el-radio v-model="formData.isRelateDeduction" :label="1">是</el-radio>
            <el-radio v-model="formData.isRelateDeduction" :label="0">否</el-radio>
          </div>
        </c-list-item>
        <c-list-item label="申请说明" prop="exceptionDesc" :span="3" label-width="100px">
          <el-input v-model="formData.exceptionDesc" type="textarea" maxlength="1024" show-word-limit :autosize="{minRows:3}" placeholder="申请说明" clearable />
        </c-list-item>
        <!-- <c-list-item prop="shopExceptionDetailDTOS" /> -->
      </c-list>
    </c-section>
    <RD title="关联图纸" :params-raw="paramsRaw" interface-path="/slm-admin/api/v1/shopDesignPicture/getUnConnectPic" :other-filters="otherFilters" @change="changeDrawingHandle" />
    <div class="btn-container">
      <c-button @click="cancelHandle">取消</c-button>
      <c-button type="primary" @click="confirmHandle">确定</c-button>
    </div>
  </div>
</template>
<script>
import RD from './addEdit/components/rd'
import { getGetOneByid, postUnDecWithPic } from '@/api/decorate'
import { otherFiltersItem } from '@/utils'
export default {
  name: 'DecorateNoDecoration',
  components: {
    RD
  },
  data() {
    const validatorDraw = (r, v, c) => {
      if (v.length === 0) {
        c()
      } else {
        c(new Error('请选择图纸'))
      }
    }
    return {
      // 当前门店建设项目号下，没有被装修任务引用的（删除状态不统计）
      // 、是否重复设计值为“否”、图纸进度值为“已完成‘的图纸数据；
      // TODO:具体条件待写
      otherFilters: [
        otherFiltersItem('picType', 'SG', '='),
        otherFiltersItem('schedule', 'F', '='),
        otherFiltersItem('constCode', this.$route.query.constCode, '='),
        otherFiltersItem('isOutpicUndecoration', '0', '='),
        otherFiltersItem('isRedesign', 0, '=')
      ],
      paramsRaw: {
        decorationTaskCode: this.$route.query.decorationTaskCode
      },
      formData: {
        exceptionDesc: '',
        customerManagerCode: '',
        isRelateDeduction: undefined,
        customerManagerName: '',
        shopExceptionDetailDTOS: []
      },
      formRules: {
        exceptionDesc: [{ required: true, message: '请输入申请说明', trigger: 'change' }],
        shopExceptionDetailDTOS: [{ required: true, validator: validatorDraw, trigger: 'change' }]
      },
      detail: {}
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    getDetail() {
      const { id } = this.$route.query
      if (!id) {
        this.$message.error('id不存在！')
        return
      }
      getGetOneByid(id).then(res => {
        this.detail = res.data
      })
    },
    // 图纸
    changeDrawingHandle(v) {
      this.formData.shopExceptionDetailDTOS = v
    },
    cancelHandle() {
      this.$store.dispatch('views/goFirst')
    },
    confirmHandle() {
      return this.$refs.form.validate().then(() => {
        return this.$gsec('EXCEPT010').then(([cfg, ecd]) => {
          if (this.formData.shopExceptionDetailDTOS.length === 0) {
            this.$message.warning('请选择图纸')
            return
          }
          ecd.constCode = this.detail.constCode
          ecd.bizCode = this.detail.decorationTaskCode
          ecd.modelId = this.detail.id
          ecd.customerManagerCode = this.formData.customerManagerCode
          ecd.customerManagerName = this.formData.customerManagerName
          ecd.exceptionDesc = this.formData.exceptionDesc
          ecd.shopExceptionDetailDTOS = this.formData.shopExceptionDetailDTOS.map(e => {
            const t = this.$gsed()
            t.picTaskCode = e.picTaskCode
            t.isRelateDeduction = this.formData.isRelateDeduction
            return t
          })
          const data = {
            exceptionDTO: ecd,
            ...this.detail
          }
          return postUnDecWithPic(data).then(res => {
            this.$message.success('操作成功！')
            this.$store.dispatch('views/goFirst')
          })
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.no-decoration{

}
</style>
